package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.purchaseapplication.LindiPurchaseApplicationApprovalVO;
import com.minimalist.common.entity.lindi.vo.purchaseapplication.LindiPurchaseApplicationQueryVO;
import com.minimalist.common.entity.lindi.vo.purchaseapplication.LindiPurchaseApplicationVO;
import com.minimalist.common.feign.client.lindi.LindiPurchaseApplicationFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地指标交易平台_指标购买申请Feign客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author 11987
 */
@Component
public class LindiPurchaseApplicationFeignClientFallbackFactory extends BaseFallbackFactory<LindiPurchaseApplicationFeignClient> {
    private static final Logger log = LoggerFactory.getLogger(LindiPurchaseApplicationFeignClientFallbackFactory.class);

    @Override
    public LindiPurchaseApplicationFeignClient create(Throwable cause) {
        return new LindiPurchaseApplicationFeignClient() {

            @Override
            public R<?> addPurchaseApplication(LindiPurchaseApplicationVO purchaseApplicationVO) {
                logServiceUnavailable("添加指标购买申请", purchaseApplicationVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "添加指标购买申请失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deletePurchaseApplicationByPurchaseApplicationId(Long purchaseApplicationId) {
                logServiceUnavailable("删除指标购买申请", purchaseApplicationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除指标购买申请失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updatePurchaseApplicationByPurchaseApplicationId(LindiPurchaseApplicationVO purchaseApplicationVO) {
                logServiceUnavailable("修改指标购买申请", purchaseApplicationVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "修改指标购买申请失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiPurchaseApplicationVO>> getPagePurchaseApplicationList(LindiPurchaseApplicationQueryVO queryVO) {
                logServiceUnavailable("分页查询指标购买申请列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "分页查询指标购买申请列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiPurchaseApplicationVO> getPurchaseApplicationByPurchaseApplicationId(Long purchaseApplicationId) {
                logServiceUnavailable("根据购买申请ID查询指标购买申请", purchaseApplicationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "根据购买申请ID查询指标购买申请失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> approvePurchaseApplication(LindiPurchaseApplicationApprovalVO approvalVO) {
                logServiceUnavailable("审批指标购买申请", approvalVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "审批指标购买申请失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deletePurchaseApplicationFileByFileId(Long fileId) {
                logServiceUnavailable("删除指标购买申请文件", fileId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除指标购买申请文件失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}